/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class SQLServerDB {

    static Connection conn;

    public SQLServerDB() {
        conn = getConn();
    }

    public static Connection getConn() {
        try {
            if (conn != null && !conn.isClosed()) {
                return conn;
            }
        } catch (SQLException ex) {
            Logger.getLogger(SQLServerDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=EmployeeData", "sa", "Snorgare158");
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(SQLServerDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return conn;
    }

    public static void closeConn(Connection conn) {
        try {
            if (!conn.isClosed()) {
                conn.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(SQLServerDB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
